package iec104_client

func writeHandler(client *Iec104Client) {

	client.options.Logger.Info("Iec104 写协程启动")
	client.goroutineWaitGroup.Add(1)
	defer func() {
		client.contextCancelFunc()
		client.goroutineWaitGroup.Done()
		client.options.Logger.Info("Iec104 写协程 停止")
	}()

	for {
		select {
		case <-client.context.Done():
			return
		case data := <-client.writeChan:
			//todo 写重试
			client.options.Logger.Debugf("发送﹥﹥ % X", data)
			printWriteMsg(client.options.Logger, data)

			_, err := client.conn.Write(data)
			if err != nil {
				//todo 如果断开，要通知重连
				return
			}
		}
	}

}
